package me.leiusual.sharing.ui.useraccount.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.view_holder_user_account.*
import me.leiusual.sharing.api.model.UserAccount
import me.leiusual.sharing.util.extension.toSpanned

/**
 * author: leiusual
 * create on: 2019-08-06
 * description:
 */
class UserAccountViewHolder(
    private val type: String,
    override val containerView: View,
    private val clickListener: (UserAccount) -> Unit
) : RecyclerView.ViewHolder(containerView), LayoutContainer, View.OnClickListener {

  private lateinit var userAccount: UserAccount

  init {
    containerView.setOnClickListener(this)
  }

  fun bind(userAccount: UserAccount) {
    this.userAccount = userAccount

    when (type) {
      "user" -> {
        val builder = StringBuilder()
        builder.append("""账户：${userAccount.accountTypeName}""")
        builder.append("""<br/>余额：${userAccount.balance}""")
        text_view.text = builder.toString().toSpanned()
      }
      "store" -> {
        val builder = StringBuilder()
        builder.append("""账户：${userAccount.accountTypeName}""")
        builder.append("""<br/>余额：${userAccount.balance}""")
        builder.append("""<br/>提现冻结额度：${userAccount.withdrawCash}""")
        builder.append("""<br/>未到账额度：${userAccount.notArrivedBalance}""")
        text_view.text = builder.toString().toSpanned()
      }
    }
  }

  override fun onClick(v: View?) {
    clickListener(userAccount)
  }
}